from meiduo_again.celery_tasks.main import celery_app
import logging
from verifications import constants
from meiduo_again.celery_tasks.sms.libs.yuntongxun.sms import CCP


logger = logging.getLogger('django')
@celery_app.task(name='send_sms_code')
def send_sms_code(mobile, sms_code):
    try:
        ccp = CCP()
        # ccp.send_template_sms('15501181635', ['1234', 5], 1)
        expires = constants.SMS_CODE_REDIS_EXPIRES // 60

        result = ccp.send_template_sms(mobile, [sms_code, expires], constants.SMS_CODE_TEMP_ID)
    except Exception as e:
        logger.error('发送短信异常%s,%s' % (mobile, e))
    else:
        if result == 0:
            logger.info('短信发送成功%s %s' % (mobile, sms_code))
        else:
            logger.error('短信发送失败%s %s' % (mobile, sms_code))